#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/9/17 20:12
# @Author  : youfeng
from .data_platform_etl import DataApiPlatformETL
from .etl_wrap import ETLWrap


class DataETL(object):

    def __init__(self, log):
        self.log = log
        self.__etl_obj = DataApiPlatformETL(log)

    def get_gsxt_data(self, data_list):

        if not isinstance(data_list, list):
            self.log.error("data_list 数据类型错误: func = gsxt type = {}".format(type(data_list)))
            return ETLWrap.empty_wrap()

        result_list = []
        for item in data_list:
            result = self.__etl_obj.gsxt_etl(item)
            if result is None:
                continue

            result_list.append(result)

        return ETLWrap.result_wrap(result_list)

    def get_wenshu_data(self, data_list):
        if not isinstance(data_list, list):
            self.log.error("data_list 数据类型错误: func = wenshu type = {}".format(type(data_list)))
            return ETLWrap.empty_wrap()

        result_list = []
        for item in data_list:
            result = self.__etl_obj.wenshu_etl(item)
            if result is None:
                continue

            result_list.append(result)

        return ETLWrap.result_wrap(result_list)

    def get_news_data(self, data_list):
        if not isinstance(data_list, list):
            self.log.error("data_list 数据类型错误: func = news type = {}".format(type(data_list)))
            return ETLWrap.empty_wrap()

        result_list = []
        for item in data_list:
            result = self.__etl_obj.news_etl(item)
            if result is None:
                continue

            result_list.append(result)

        return ETLWrap.result_wrap(result_list)

    def get_zhixing_data(self, data_list):
        if not isinstance(data_list, list):
            self.log.error("data_list 数据类型错误: func = zhixing type = {}".format(type(data_list)))
            return ETLWrap.empty_wrap()

        result_list = []
        for item in data_list:
            result = self.__etl_obj.zhixing_etl(item)
            if result is None:
                continue

            result_list.append(result)

        return ETLWrap.result_wrap(result_list)

    def get_shixin_data(self, data_list):
        if not isinstance(data_list, list):
            self.log.error("data_list 数据类型错误: func = shixin type = {}".format(type(data_list)))
            return ETLWrap.empty_wrap()

        result_list = []
        for item in data_list:
            result = self.__etl_obj.shixin_etl(item)
            if result is None:
                continue

            result_list.append(result)

        return ETLWrap.result_wrap(result_list)
